package com.wangp.mywrite.coding;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author: wp
 * @date: 2023/5/19 15:28:03
 * @desc:
 **/
public class Combine {

    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> path = new ArrayList<>();
        dfs(res, path, n, k, 1);
        return res;
    }

    private void dfs(List<List<Integer>> res, List<Integer> path, int n, int k, int startIndex) {
        if (path.size() == k) {
            res.add(new ArrayList<>(path));
            return;
        }
        for (int i = startIndex; i <= n; i++) {
            path.add(i);
            dfs(res, path, n, k, i + 1);
            path.remove(Integer.valueOf(i));
        }
    }

    public static void main(String[] args) {
        System.out.println(new Combine().combine(4, 3));
    }
}
